<template>
  <div class="table-main">
    <el-dialog
      @close="handMyClose"
      :append-to-body="true"
      title="汽车服务"
      :visible.sync="dialogVisible1"
      width="60%"
      :close-on-click-modal="false"
    >
      <div style="margin-top:50px;">
        <el-form ref="form" :model="form" label-width="120px" :rules="rules">
          <el-row :gutter="20" justify="center" type="flex">
            <el-col :span="16">
              <el-form-item label="用户姓名:" prop="trueName">
                <el-input :disabled="isShow==3" v-model="form.trueName" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" justify="center" type="flex">
            <el-col :span="16">
              <el-form-item label="公交电子卡号:" prop="carNo">
                <el-input :disabled="isShow==3" v-model="form.carNo" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" justify="center" type="flex">
            <el-col :span="16">
              <el-form-item label="用户手机号" prop="phone">
                <el-input :disabled="isShow==3" v-model="form.phone" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" justify="center" type="flex">
            <el-col :span="16">
              <el-form-item label="余额" prop="moeny">
                <el-input :disabled="isShow==3" v-model="form.moeny" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">取 消</el-button>
        <el-button
          type="primary"
          @click="handFromSub('form')"
          :loading="bntLoading"
          v-if="isShow!=3"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { imgSizi } from '@/utils/myUtils'
export default {
  name: 'SidebarLogo',
  components: {},
  watch: {
    isState(newObj) {
      this.isShow = newObj
    }
  },
  props: {
    isState: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      bntLoading: false,
      loading2: false,
      rules: {
        redictUrl: [
          { required: true, message: '请输入跳转地址', trigger: 'blur' }
        ],
        imageTitle: [
          { required: true, message: '请输入轮播图名字', trigger: 'blur' }
        ],
        resPath: [{ required: true, message: '请上传轮播图' }]
      },
      headers: {
        token: localStorage.getItem('mytoken') || ''
      },
      form: {
        vipDetails: []
      },
      shopStatusOptions: [],
      isShow: 0,
      imageUrl: '',
      dialogImageUrl: '',
      dialogVisible1: false,
      addressKeyword: '',
      activeName: 'first',
      dialogVisible: false,
      tipShow: false,
      findAllsList: []
    }
  },
  async mounted() {
    this.findAllsList = (await this.$api.userByShop()).data.data
  },
  methods: {
    handDel(item, index) {
      console.log(item, index)
      this.form.vipDetails.splice(index, 1)
    },
    handEdit(item) {
      item.ifShow = false
      console.log(this.form)
    },
    handAdd() {
      this.form.vipDetails.push({
        keyName: '',
        valueNum: '',
        remaker: '',
        ifShow: true
      })
    },
    handSeleDel() {},
    uploadChange() {},
    onError() {},
    handGetShop(id) {
      this.$api.selectUserCardByIdUserCard({ id }).then(res => {
        this.form = res.data.data
        console.log('查询轮播详情2', res)
      })
    },
    handSuccess(res, file) {
      var url = JSON.parse(res.message)
      this.$set(this.form, 'icon', url.url)
      this.loading2 = false
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!')
      }
      return isSize
    },
    handSuccess2(res, file) {
      var url = JSON.parse(res.message)
      this.$set(this.form, 'img', url.url)
      this.loading2 = false
    },
    beforeAvatarUpload2(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!')
      }
      return isSize
    },
    handMyClose() {
      this.$refs.form.resetFields()
      this.$parent.closeFrom()
    },
    handFromSub(formName) {
      //1编辑
      if (this.isState == 1) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.bntLoading = true
            this.$api
              .editVip(this.form)
              .then(res => {
                this.dialogVisible1 = false
                this.$parent.init()
                console.log(res, '编辑', this.form)
                this.$message({
                  message: res.data.message,
                  type: 'success'
                })
                this.bntLoading = false
              })
              .finally(() => {
                this.bntLoading = false
              })
          } else {
            console.log('error submit!!')
            this.$message({
              message: '请完成表单录入'
            })
            this.bntLoading = false
            return false
          }
        })
      } else if (this.isState == 0) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            // this.form.vipDetails = JSON.stringify(this.form.vipDetails)
            this.bntLoading = true
            this.$api
              .addVip(this.form)
              .then(res => {
                this.dialogVisible1 = false
                this.bntLoading = false
                this.$parent.init()
                this.$refs.form.resetFields()
                console.log(res, '添加vip,表单验证', this.form)
                this.$message({
                  message: res.data.message,
                  type: 'success'
                })
              })
              .finally(() => {
                this.bntLoading = false
              })
          } else {
            console.log('error submit!!')
            this.$message({
              message: '请完成表单录入'
            })
            return false
          }
        })
      }
    },

    // handSuccess(response, file, fileList) {
    //   console.log(response, file, fileList, '成功回调')
    //   this.form.shopImg = response.message
    // },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    // handlePictureCardPreview(file) {
    //   this.dialogImageUrl = file.url
    //   this.dialogVisible2 = true
    // },
    handleClose() {
      this.dialogVisible = false
    },
    handMapShow() {
      this.dialogVisible = true
    },
    handleClick() {}
  }
}
</script>

<style lang="scss" scoped>
.vipProjeck {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .pro_item {
    width: 20%;
  }
}
.map_btn {
  width: 82px;
  height: 22px;
  background: rgba(56, 173, 147, 1);
  border-radius: 4px;
  color: #fff;
  font-size: 14px;
  line-height: 22px;
  text-align: center;
  margin-top: 8px;
}
/deep/ .el-form-item__label {
  font-size: 14px;
  color: #000;
  font-weight: bold;
}
.form_box {
  width: 80%;
  margin: 0 auto;
}
.avatar-uploader /deep/ .el-upload {
  border: 1px dashed #38ad93;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #38ad93;
  width: 56px;
  height: 44px;
  line-height: 44px;
  text-align: center;
}
.avatar {
  width: 56px;
  height: 44px;
  display: block;
}
.avatar-uploader-icon2 {
  font-size: 28px;
  color: #38ad93;
  width: 351px;
  height: 192px;
  line-height: 192px;
  text-align: center;
}
.avatar2 {
  width: 351px;
  height: 192px;
  display: block;
}
</style>
